package uk.ac.lkl.common.allocator.ui;

import javax.swing.JLabel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import uk.ac.lkl.lpp.model.ldo.LearningEntity;
/**
 * A label for the side of the allocate table
 * @author Uri
 */
public class AllocateLabel extends JLabel{
	String fullText;
	int length=10;
	
	public AllocateLabel(Object o){
		setText(o.toString());
		if (o instanceof LearningEntity)
        ((LearningEntity)o).addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                setText(e.getSource().toString());
            }
        });

	}
	
	public void setText(String label) {
		fullText=label;
		if(label.length()>length){
			label=label.substring(0, length-3);
			label=label.concat("...");
		}
		setToolTipText(fullText);
		super.setText(label);
		
	}
}
